//
//  ADMacros.h
//  ADKit
//
//  Created by duzexu on 2017/11/30.
//  Copyright © 2017年 duzexu. All rights reserved.
//

#ifndef ADMacros_h
#define ADMacros_h

/// Log
#define NSLogV(x) LxDBAnyVar(x)
#define NSLog(format, ...) LxPrintf(@"[ADLog]" format, ##__VA_ARGS__)
#if ENABLE_GodEye
#define ADLog(fmt, ...) [Log4G log:[NSString stringWithFormat:@"[ADLog]" fmt, ##__VA_ARGS__] file:[NSString stringWithFormat:@"%s",__FILE__] line:__LINE__ function:[NSString stringWithFormat:@"%s",__FUNCTION__]]
#define ADLogWarning(fmt, ...) [Log4G warning:[NSString stringWithFormat:@"[ADLog]" fmt, ##__VA_ARGS__] file:[NSString stringWithFormat:@"%s",__FILE__] line:__LINE__ function:[NSString stringWithFormat:@"%s",__FUNCTION__]]
#define ADLogError(fmt, ...) [Log4G error:[NSString stringWithFormat:@"[ADLog]" fmt, ##__VA_ARGS__] file:[NSString stringWithFormat:@"%s",__FILE__] line:__LINE__ function:[NSString stringWithFormat:@"%s",__FUNCTION__]]
#elif DEBUG
#define ADLog(fmt, ...) NSLog(fmt, ##__VA_ARGS__)
#define ADLogWarning(fmt, ...) NSLog(fmt @"[Warning]", ##__VA_ARGS__)
#define ADLogError(fmt, ...) NSLog(fmt @"[Error]", ##__VA_ARGS__)
#else
#define ADLog(fmt, ...)
#define ADLogWarning(fmt, ...)
#define ADLogError(fmt, ...)
#endif

/// color
#define AD_RGB(__r, __g, __b) [UIColor colorWithRed:(__r / 255.0) green:(__g / 255.0) blue:(__b / 255.0) alpha:1]
#define AD_RGBA(__r, __g, __b, __a) [UIColor colorWithRed:(__r / 255.0) green:(__g / 255.0) blue:(__b / 255.0) alpha:__a]
#define AD_HEX(__hex) [UIColor colorWithHexString:__hex]

/// TODO Warning
#define STRINGIFY(S) #S
#define DEFER_STRINGIFY(S) STRINGIFY(S)
#define PRAGMA_MESSAGE(MSG) _Pragma(STRINGIFY(message(MSG)))
#define FORMATTED_MESSAGE(MSG) "[TODO-" DEFER_STRINGIFY(__COUNTER__) "] " MSG " \n" DEFER_STRINGIFY(__FILE__) " line " DEFER_STRINGIFY(__LINE__)
#define KEYWORDIFY try {} @catch (...) {}
#define TODO(MSG) KEYWORDIFY PRAGMA_MESSAGE(FORMATTED_MESSAGE(MSG))

#define AD_IS_iPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define AD_IS_iPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define AD_IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

/// 屏幕尺寸相关
#define AD_SCREEN_WIDTH  ([[UIScreen mainScreen] bounds].size.width)
#define AD_SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define AD_APP_WIDTH [[UIScreen mainScreen] applicationFrame].size.width
#define AD_APP_HEIGHT [[UIScreen mainScreen] applicationFrame].size.height
#define AD_APP_ORIENTATION [[UIApplication sharedApplication] statusBarOrientation]
#define AD_IS_PORTRAIT UIInterfaceOrientationIsPortrait(AD_APP_ORIENTATION)
#define AD_SCREEN_BOUNDS ([[UIScreen mainScreen] bounds])
#define AD_SCREEN_MAX_LENGTH (MAX(AD_SCREEN_WIDTH, AD_SCREEN_HEIGHT))
#define AD_SCREEN_MIN_LENGTH (MIN(AD_SCREEN_WIDTH, AD_SCREEN_HEIGHT))

#define AD_WIDTH (AD_IS_PORTRAIT ? AD_SCREEN_MIN_LENGTH : AD_SCREEN_MAX_LENGTH)
#define AD_HEIGHT (AD_IS_PORTRAIT ? AD_SCREEN_MAX_LENGTH : AD_SCREEN_MIN_LENGTH)
#define AD_RECT CGRectMake(0, 0, AD_WIDTH, AD_HEIGHT)

/// 手机类型相关
#define AD_IS_IPHONE_4_OR_LESS  (AD_IS_iPhone && AD_SCREEN_MAX_LENGTH  < 568.0)
#define AD_IS_IPHONE_5          (AD_IS_iPhone && AD_SCREEN_MAX_LENGTH == 568.0)
#define AD_IS_IPHONE_6          (AD_IS_iPhone && AD_SCREEN_MAX_LENGTH == 667.0)
#define AD_IS_IPHONE_6P         (AD_IS_iPhone && AD_SCREEN_MAX_LENGTH == 736.0)
#define AD_IS_IPHONE_X          (AD_IS_iPhone && AD_SCREEN_MAX_LENGTH >= 812.0)

/// 导航条高度
#define AD_APPLICATION_TOP_BAR_HEIGHT (AD_IS_IPHONE_X?88.0f:64.0f)
#define AD_APPLICATION_TOP_BAR_OFFSET (AD_IS_IPHONE_X?24.0f:0.0f)
/// tabBar高度
#define AD_APPLICATION_TAB_BAR_HEIGHT (AD_IS_IPHONE_X?83.0f:49.0f)
#define AD_APPLICATION_TAB_BAR_OFFSET (AD_IS_IPHONE_X?34.0f:0.0f)
/// 工具条高度 (常见的高度)
#define AD_APPLICATION_TOOL_BAR_HEIGHT_44  44.0f
#define AD_APPLICATION_TOOL_BAR_HEIGHT_49  49.0f

#define AD_APPLICATION_TOOL_BAR_HEIGHT_110  110.0f

/// 状态栏高度
#define AD_APPLICATION_STATUS_BAR_HEIGHT (AD_IS_IPHONE_X?44.0f:20.0f)

#define AD_SAFEAREAINSETS_PORTRAIT (AD_IS_IPHONE_X?UIEdgeInsetsMake(44, 0, 34, 0):UIEdgeInsetsMake(44, 0, 0, 0))
#define AD_SAFEAREAINSETS_LANDSCAPE (AD_IS_IPHONE_X?UIEdgeInsetsMake(0, 44, 21, 44):UIEdgeInsetsMake(0, 0, 0, 0))

#define AD_STRING(x) @(x).stringValue

// .h文件
#define AD_SINGLETON_H + (instancetype)sharedInstance;\
+ (instancetype)alloc __attribute__((unavailable("call sharedInstance instead")));\
+ (instancetype)new __attribute__((unavailable("call sharedInstance instead")));\
- (instancetype)copy __attribute__((unavailable("call sharedInstance instead")));\
- (instancetype)mutableCopy __attribute__((unavailable("call sharedInstance instead")));
// .m文件
#define AD_SINGLETON_M \
static id _instace; \
+ (instancetype)sharedInstance \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instace = [[super alloc] init]; \
}); \
return _instace; \
}

#endif /* ADMacros_h */
